import request from '@/utils/request';

/**
 * 自习室管理API
 */

// 分页查询自习室列表
export const getRoomListAPI = (params) => {
  return request({
    url: '/room/list',
    method: 'get',
    params
  });
};

// 获取自习室详细信息
export const getRoomInfoAPI = (id) => {
  return request({
    url: `/room/${id}`,
    method: 'get'
  });
};

// 新增自习室
export const addRoomAPI = (roomData) => {
  return request({
    url: '/room',
    method: 'post',
    data: roomData
  });
};

// 修改自习室
export const updateRoomAPI = (roomData) => {
  return request({
    url: '/room',
    method: 'put',
    data: roomData
  });
};

// 删除自习室
export const deleteRoomAPI = (ids) => {
  return request({
    url: '/room/' + ids.map(id => Number(id)).join(','), // 确保转换为数字
    method: 'delete'
  });
};

// 上传自习室封面
export function uploadRoomCoverAPI(data) {
  return request({
    url: '/room/uploadCover',
    method: 'post',
    data: data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 查询自习室下的所有座位
export const getRoomSeatsAPI = (roomId, params) => {
  return request({
    url: `/room/${roomId}/seats`,
    method: 'get',
    params
  });
};
